#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const  ll N = 1e6 + 10, INF = 0x3f3f3f3f;

struct node { pair< ll, ll> s, t; };

ll n, x;
vector<node> a;

bool check(ll w)
{
    ll sum = 0;
    for (ll i = 0;i < n;i++) {
        auto [s, t] = a[i];
        if ((1.0 * s.first) / s.second < (1.0 * t.first) / t.second) swap(s, t);
        ll res = INF;
        for (ll cntt = 0;cntt <= 100;cntt++) {
            ll sw = w - cntt * t.first;
            ll cnts = (sw + s.first - 1) / s.first;
            res = min(res, cnts * s.second + cntt * t.second);
        }
        sum += res;
        if (sum > x) return 0;
    }
    return 1;
}

void solve()
{
    cin >> n >> x;
    for (ll i = 0;i < n;i++) {
        pair< ll, ll> s, t;
        cin >> s.first >> s.second >> t.first >> t.second;
        a.push_back({ s,t });
    }
    ll l = 0, r = 1e9;
    while (l < r) {
        ll mid = (l + r + 1) >> 1;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}